<template>
  <div class="jobdetail-box ct">
    <el-breadcrumb class="head-nav" :separator-icon="ArrowRight">
      <el-breadcrumb-item :to="{ path: '/yardhome', query: {yardId}  }">站院首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/yardnews',query: {yardId}  }">站院动态</el-breadcrumb-item>
      <el-breadcrumb-item :to="{path: titlePath1 ,query: {yardId}}">{{ tite1 }}</el-breadcrumb-item>
      <el-breadcrumb-item>{{ tite2 }}</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="detail-content">
      <div class="content-l">
        <div class="content-head">
          <div class="h3">{{ artice[title3] }}</div>
          <div class="sp tac">{{ artice.createdTime }} 浏览数：{{ artice.pageView }}次</div>
        </div>

        <div class="details">
          <div class="details-d" v-if="artice.videoUrl">
            <video width="100%" height="500" muted controls autoplay="autoplay" preload>
              <source :src="artice.videoUrl" type="video/mp4">
              您的浏览器不支持 video 标签。
            </video>
          </div>
          <div class="details-d" v-else v-html="artice[contentKey]"></div>
          <!-- <div class="sp">2024年，这是一段长文那本，这是一段长文那本这是一段长文那本这是一段长文那本这是一段长文那本这是一段长文那本，这是一段长文那本2024年，这是一段长文那本，这是一段长文那本这是一段长文那本这是一段长文那本这是一段长文那本这是一段长文那本，这是一段长文那本</div>
          <div class="sp">2024年，这是一段长文那本，这是一段长文那本这是一段长文那本这是本</div>
          <img src="../../assets/21.jpeg" alt="">
          <div class="sp">2024年，这是一段长文那本，这是一段长文那本这是一段长文那本这是本</div>
          <div class="sp">2024年，这是一段长文那本，这是一段长文那本这是一段长文那本这是本</div>
          <img src="../../assets/21.jpeg" alt="">
          <div class="sp">2024年，这是一段长文那本，这是一段长文那本这是一段长文那本这是本</div>
          <div class="sp">2024年，这是一段长文那本，这是一段长文那本这是一段长文那本这是本</div>
          <img src="../../assets/21.jpeg" alt="">
          <div class="sp">2024年，这是一段长文那本，这是一段长文那本这是一段长文那本这是本</div>
          <div class="sp">2024年，这是一段长文那本，这是一段长文那本这是一段长文那本这是本</div>
        </div>

        <div class="b-nav">
          <div class="o">上一篇： 科技小院这是一段长文那本，这是一这是一段长文那本，这是一这是一段长文那本，这是一科技小院这是一段长文那本，这是一这是一段长文那本，这是一这是一段长文那本，这是一</div>
          <div class="o">下一篇： 科技小院这是一段长文那本，这是一这是一段长文那本，这是一这是一段一</div> -->
        </div>
      </div>
      <div class="content-r">
        <div>暂无</div>
        <div>扫描二维码关注更多内容</div>
        <img src="../../assets/job/7.jpg" alt="">
      </div>
    </div>
  </div>
</template>
<script setup>
import { ArrowRight } from '@element-plus/icons-vue'
import { getWorkStateById, getBulletinById, getPoliciesRegulationsById, getScientificResearchById, getCourtyardLogById } from '@/api/home'
import { useRouter } from 'vue-router';
import { computed, ref, onMounted } from 'vue'

const dataMap = {
  job: {
    func: getWorkStateById,
    title: '工作动态',
    detail: '动态详情',
    key: 'workId',
    contentKey: 'workContent',
    pageTitle: 'workTitle',
    titlePath: '/yardnews/yardnewsmore',
  },
  bulletin: {
    func: getBulletinById,
    title: '通知公告',
    detail: '公告详情',
    key: 'bulletinId',
    contentKey: 'bulletinContent',
    pageTitle: 'bulletinTitle',
    titlePath: '/yardnews/yardnoticemore'
  },
  policy: {
    func: getPoliciesRegulationsById,
    title: '政策法规',
    detail: '法规详情',
    key: 'policiesId',
    contentKey: 'policiesContent',
    pageTitle: 'policiesTitle',
    titlePath: '/yardnews/yardnewsmore'
  },
  science: {
    func: getScientificResearchById,
    title: '科学研究',
    detail: '研究详情',
    key: 'researchId',
    contentKey: 'researchContent',
    pageTitle: 'researchTitle',
    titlePath: '/yardnews/yardsciencemore'
  },
  yardlog: {
    func: getCourtyardLogById,
    title: '站院日志',
    detail: '日志详情',
    key: 'logId',
    contentKey: 'logContent',
    pageTitle: 'logTitle',
    titlePath: '/yardnews/yardlogsmore'
  },
  // 根据category参数映射到对应的配置
  news_report: {
    func: getWorkStateById,
    title: '站院动态',
    detail: '动态详情',
    key: 'bulletinId',
    contentKey: 'workContent',
    pageTitle: 'workTitle',
    titlePath: '/yardnews/yardnewsmore',
  },
  field_trial: {
    func: getWorkStateById,
    title: '田间示范',
    detail: '试验详情',
    key: 'bulletinId',
    contentKey: 'workContent',
    pageTitle: 'workTitle',
    titlePath: '/yardnews/yardnewsmore',
  },
  tech_support: {
    func: getWorkStateById,
    title: '科技助农',
    detail: '助农详情',
    key: 'bulletinId',
    contentKey: 'workContent',
    pageTitle: 'workTitle',
    titlePath: '/yardnews/yardnewsmore',
  },
  public_class: {
    func: getWorkStateById,
    title: '公益课堂',
    detail: '课堂详情',
    key: 'bulletinId',
    contentKey: 'workContent',
    pageTitle: 'workTitle',
    titlePath: '/yardnews/yardnewsmore',
  },
  summer_school: {
    func: getWorkStateById,
    title: '暑期学校',
    detail: '学校详情',
    key: 'bulletinId',
    contentKey: 'workContent',
    pageTitle: 'workTitle',
    titlePath: '/yardnews/yardnewsmore',
  }
}

const router = useRouter();
console.log('00router', router)
const id = computed(()=>router?.currentRoute?.value?.params.id);
const yardId = computed(()=>router?.currentRoute?.value?.query.yardId);
const type = computed(()=>router?.currentRoute?.value?.query.type);
const category = computed(()=>router?.currentRoute?.value?.query.category);

// 优先使用category参数，如果没有则使用type参数
const currentConfig = computed(() => {
  if (category.value && dataMap[category.value]) {
    return dataMap[category.value];
  }
  return dataMap[type.value];
});

const tite1 = computed(() => {
  return currentConfig.value?.title
})
const tite2 = computed(() => {
  return currentConfig.value?.detail
})
const contentKey = computed(() => {
  return currentConfig.value?.contentKey
})
const title3 = computed(() => {
  return currentConfig.value?.pageTitle
})
const titlePath1 = computed(() => {
  return currentConfig.value?.titlePath
})
const artice = ref({});
onMounted(async () => {
  console.log('--',router?.currentRoute?.value)
  const func = currentConfig.value?.func;
  const ret = await func({ [currentConfig.value?.key]: id.value })
  console.log('00ret', ret)
  artice.value = ret?.data
})

</script>
<style lang="scss" scoped>
.jobdetail-box {
  padding: 0 10%;
  flex: 1;
  width: 100%;
  background: #f8f8f8 url('../../assets/job/6.png') no-repeat 0 200px;
  color: #666;

  .head-nav {
    height: 125px;
    display: flex;
    align-items: center;
    font-size: 24px;
  }

  .detail-content {
    display: flex;
    margin-bottom: 60px;
    flex: 1;
    min-height: 1000px;
    font-family: "SimSun", "宋体", "PingFang SC", "Microsoft YaHei", sans-serif;

    .content-l {
      background-color: #fff;
      margin-right: 40px;
      padding: 30px;
      color: #666;
      font-size: 20px;
      min-height: 100%;
      position: relative;
      padding-bottom: 112px;
      flex: 1;
      overflow: hidden;

      .b-nav {
        color: #666;
        position: absolute;
        height: 112px;
        width: 100%;
        bottom: 0;
        left: 0;
        display: flex;
        align-items: flex-start;
        flex-direction: column;
        justify-content: center;
        padding-left: 30px;
        padding-right: 30px;

        .o {
          width: 100%;
          height: 30px;
          cursor: pointer;
        }
      }

      .content-head {
        padding-bottom: 15px;
      }

      .h3 {
        font-weight: bold;
        font-size: 32px;
        color: #000;
        display: flex;
        justify-content: center;

      }

      .sp {
        line-height: 32px;
        //text-indent: 4%;
      }

      img {
        width: 100%;
        height: 380px;
        object-fit: contain;
        margin: 10px 0;
      }

      .details {
        border-top: 2px solid #e5e5e5;
        border-bottom: 2px solid #e5e5e5;
        padding: 20px 0;
        height: 100%
      }

      :deep(.details-d) {
        text-indent: 4%;

        div, p {
          line-height: 40px;
          font-size: 22px;
        }
        img {
          width: 100%;
          height: 500px;
          object-fit: contain;
          margin: 20px 0;
        }
      }
    }

    .content-r {
      display: flex;
      flex-direction: column;
      align-items: center;
      font-size: 20px;
      background-color: #fff;
      align-self: flex-start;
      padding: 20px;
      width: 300px;

      img {
        width: 300px;
        // height: 360px;
        object-fit: cover;
      }
    }
  }
}
</style>